﻿$(document).ready(function () {

    for (var i = 1; i <= 6; i++) {
        $('#sadrzaj_' + i + 'ime').css({ "display": "none" });
        $('#sadrzaj_' + i).css({ "display": "none" });
    }

    $.ajax({
        type: "POST",
        url: "KorisnickiUtility.asmx/NajnovijiClanciDrveceThumbs",
        data: "{}",
        contentType: "application/json",
        dataType: "json",
        success: function (data) {

            for (var i = 1; i <= data.d.length; i++) {
                $('#sadrzaj_' + i).css({ "background-image": "url('" + data.d[i - 1].linkThumb + "')", "display": "block" });
                $('#sadrzaj_' + i + 'ime').text(data.d[i - 1].nazivDrveta);
                $('#sadrzaj_' + i + 'ime').css({ "display": "block" });
            }





        }
    });

    $("#naprijed").click(function () {
        $("#sadrzaj_najnovije_drvece").animate({
            left: -4
        });
    });

    $("#natrag").click(function () {
        $("#sadrzaj_najnovije_drvece").animate({
            left: -705
        });
    });

    $(".clanak").click(function () {
        var naziv = $(".sadrzaj_ime", this).text();
        $.ajax({
            type: "POST",
            url: "KorisnickiUtility.asmx/DrvoID",
            data: JSON.stringify({ hrvatskiNaziv: naziv }),
            contentType: "application/json",
            dataType: "json",
            success: function (data) {
                window.location.href = "drvo.aspx?id=" + data.d;
            }
        });
    });

    $(".clanak").hover(
      function () {
          $(this).find(".sadrzaj_otvori").fadeIn(1000);
      },
      function () {
          $(this).find(".sadrzaj_otvori").fadeOut(200);
      }
    );

});